package com.tangsm.api.demo.service.impl;

import com.tangsm.api.demo.domain.Order;
import com.tangsm.api.demo.service.OrderService;
import com.tangsm.api.demo.strategy.AbstractHandler;
import com.tangsm.api.demo.strategy.HandlerContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: CipherCui
 * @Description:
 * @Date: Created in 9:54 2019/2/2
 */
@Service
public class OrderServiceImpl implements OrderService {
    private static final Logger log = LoggerFactory.getLogger(OrderServiceImpl.class);
    @Autowired
    private HandlerContext handlerContext;

    @Override
    public String handle(Order dto) {
        AbstractHandler handler = handlerContext.getInstance(dto.getType());
        String msg = handler.handle(dto);
        log.info("最终返回结果={}", msg);
        return msg;
    }

}